<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>

<body>
    <jsp:include page="../frame.jsp"></jsp:include>
    <div id="page-wrapper" >
        <div class="header">
            <h1 class="page-header">
                辅导员信息管理
            </h1>
            <ol class="breadcrumb">
                <li><a href="/yibinu_certificate/index">首页</a></li>
                <li><a href="/yibinu_certificate/teacher/list">辅导员信息管理</a></li>
                <li class="active">
                    <c:if test="${not empty teacher}">修改辅导员信息</c:if>
                    <c:if test="${empty teacher}">新增辅导员信息</c:if>
                </li>
            </ol>

        </div>

        <div id="page-inner">
            <div class="row">
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-action">
                            填写辅导员信息
                        </div>
                        <div class="card-content">
                            <form class="col s12" action="#">
                                <div class="row">
                                    <div class="input-field col s12">
                                        <input name="id" type="hidden" value="${teacher.id}">

                                        <input placeholder="请输入教工号" id="teacher_num" type="text" class="validate" name="teacherNum" value="${teacher.teacherNum}">
                                        <label for="teacher_num">教工号</label>
                                    </div>
                                    <div class="input-field col s12">
                                        <input placeholder="请输入辅导员登录密码" id="teacher_pwd" type="password" class="validate" name="teacherPassword" value="${teacher.teacherPassword}">
                                        <label for="teacher_pwd">辅导员登录密码</label>
                                    </div>
                                    <div class="input-field col s12">
                                        <input placeholder="请输入辅导员姓名" id="teacher_name" type="text" class="validate" name="teacherName" value="${teacher.teacherName}">
                                        <label for="teacher_name">辅导员姓名</label>
                                    </div>
                                    <div class="input-field col s12">
                                        <input placeholder="请输入辅导员电话号码" id="teacher_tel" type="text" class="validate" name="teacherTel" value="${teacher.teacherTellphone}">
                                        <label for="teacher_tel">辅导员电话号码</label>
                                    </div>
                                    <div class="input-field col s12">
                                        <input placeholder="请输入辅导员联系邮箱" id="teacher_email" type="text" class="validate" name="teacherEmail" value="${teacher.teacherEmail}">
                                        <label for="teacher_email">辅导员联系邮箱</label>
                                    </div>
                                    <div class="input-field col s12">
                                        <label for="teacher_class" style="font-size: 0.8rem;">辅导专业和班级（可多选）</label>
                                        <br>
                                        <br>
                                        <select multiple class="form-control" id="teacher_class" name="teacherClass">
                                            <c:forEach items="${majors}" var="m" varStatus="s">
                                                <c:choose>
                                                    <c:when test="${s.index == 0}">
                                                        <option value="${m.majorName}-${m.majorClass}" selected="selected">${m.majorName}-${m.majorClass}</option>
                                                    </c:when>
                                                    <c:otherwise>
                                                        <option value="${m.majorName}-${m.majorClass}">${m.majorName}-${m.majorClass}</option>
                                                    </c:otherwise>
                                                </c:choose>
                                            </c:forEach>
                                        </select>
                                    </div>
                                    <div class="input-field col s12">
                                        <label for="teacher_school" style="font-size: 0.8rem;">所属二级学院</label>
                                        <br>
                                        <br>
                                        <select class="form-control" id="teacher_school" name="teacherSchool">
                                            <c:forEach items="${schools}" var="s">
                                                <option value="${s.schoolName}">${s.schoolName}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                    <div class="input-field col s12">
                                        <button type="button" class="btn" onclick="submitForm()">提交</button>
                                        <script type="text/javascript">
                                            function submitForm() {
                                                var formData = new FormData();
                                                var check = true;
                                                var d = $('form').serializeArray();
                                                $.each(d,function () {
                                                    if (this.name != 'id' && $.trim(this.value) == ''){
                                                        alert('请填写完整相关内容');
                                                        check = false;
                                                    }else {
                                                        formData.append(this.name,this.value);
                                                    }
                                                });
                                                if (!check){
                                                    return;
                                                }
                                                $.ajax({
                                                    async:true,
                                                    type:'post',
                                                    url:'/yibinu_certificate/teacher/addTeacher',
                                                    data:formData,
                                                    processData:false,
                                                    contentType:false,
                                                    success:function (result) {
                                                        alert('操作成功');
                                                        window.location.href = "list";
                                                    }
                                                });
                                            }
                                        </script>
                                    </div>
                                </div>
                            </form>
                            <div class="clearBoth"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- /. PAGE INNER  -->
    </div>
    <!-- /. PAGE WRAPPER  -->
</div>
<!-- /. WRAPPER  -->
</body>
<script type="text/javascript">

    (function ($) {
        "use strict";
        var mainApp = {

            initFunction: function () {
                /*MENU
                ------------------------------------*/
                $('#main-menu').metisMenu();

                $(window).bind("load resize", function () {
                    if ($(this).width() < 768) {
                        $('div.sidebar-collapse').addClass('collapse')
                    } else {
                        $('div.sidebar-collapse').removeClass('collapse')
                    }
                });
            },

            initialization: function () {
                mainApp.initFunction();

            }

        }
        // Initializing ///

        $(document).ready(function () {
            $(".dropdown-button").dropdown();
            $("#sideNav").click(function(){
                if($(this).hasClass('closed')){
                    $('.navbar-side').animate({left: '0px'});
                    $(this).removeClass('closed');
                    $('#page-wrapper').animate({'margin-left' : '260px'});

                }
                else{
                    $(this).addClass('closed');
                    $('.navbar-side').animate({left: '-260px'});
                    $('#page-wrapper').animate({'margin-left' : '0px'});
                }
            });

            mainApp.initFunction();
        });

        $(".dropdown-button").dropdown();

    }(jQuery));

</script>

</html>